package com.wx.mall.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wx.mall.sys.entity.Permission;
import com.wx.mall.sys.entity.RolePermission;
import com.wx.mall.sys.mapper.RolePermissionMapper;
import com.wx.mall.sys.service.IPermissionService;
import com.wx.mall.sys.service.IRolePermissionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author j
 * @since 2020-03-18
 */
@Service
public class RolePermissionServiceImpl extends ServiceImpl<RolePermissionMapper, RolePermission> implements IRolePermissionService {

    @Autowired
    private IPermissionService service;

    @Override
    public List<Long> getListByRole(Long roleId) {
        QueryWrapper<RolePermission> wrapper=new QueryWrapper<>();
        wrapper.eq("role_id",roleId);
        List<RolePermission> list=this.list(wrapper);
        List<Long> ids=new ArrayList<>();
        for (RolePermission permission:list){

       Permission permission1=this.getById(permission.getPermissionId());
       if (permission1.getType()==2){

           ids.add(permission.getPermissionId());
       }

        }
        return ids;
    };

    private Permission getById(Long permissionId){

        Permission one=service.getById(permissionId);

   return one;
    }
}
